package data;

import java.io.Serializable;

/**
 * Represents an element of basic type data in a data object.
 * 
 * @author Richard
 * @deprecated
 */
public class DataAttribute implements Serializable {

	private static final long serialVersionUID = -3189613389300564522L;

	/**
	 * The type of data represented.
	 */
	public static enum DataAttributeType {
		INT, FLOAT, DOUBLE, BOOL, STRING, CHAR
	}

	// The name of the attribute
	private String name;
	
	// The type of attribute
	private DataAttributeType type;
	
	// The value of the attribute
	private Object value;

	/**
	 * Creates a new DataAttribute.
	 * 
	 * @param name The name of the attribute.
	 * @param type The type of the attribute.
	 */
	public DataAttribute(String name, DataAttributeType type) {
		super();
		this.name = name;
		this.type = type;
		this.value = null;
	}

	/**
	 * Accessor for the attribute's name.
	 * 
	 * @return String The attribute name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the object value cast into the appropriate basic type.
	 * 
	 * @return Object The value as an object.
	 */
	public Object getValue() {
		switch(type) {
			case INT:
				return (Integer) value;
			case FLOAT:
				return (Float) value;
			case DOUBLE:
				return (Double) value;
			case BOOL:
				return (Boolean) value;
			case STRING:
				return (String) value;
			case CHAR:
				return (Character) value;
		}
		return value;
	}

	/**
	 * Sets the value of the object value to the given value.
	 * 
	 * @param value The given value.
	 */
	public void setValue(Object value) {
		this.value = value;
	}

}
